using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.ObjectBuilder;

namespace LibrErian.Modules.BasicBook.Views.Library
{
    [SmartPart]
    public partial class LibraryView : UserControl, ILibraryView 
    {
        private LibraryViewPresenter presenter;

        [CreateNew]
        public LibraryViewPresenter Presenter
        {
            set
            {
                presenter = value;
                presenter.View = this;
            }
        }

        public LibraryView()
        {
            InitializeComponent();
        }

        private void LibraryView_Load(object sender, EventArgs e)
        {
            presenter.OnViewReady();
        }

        public void SetLibrary(Model.Library library)
        {
            libraryBindingSource.DataSource = library;
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            libraryBindingSource.EndEdit();
            presenter.OnSave();
        }

        private void tsbCancel_Click(object sender, EventArgs e)
        {
            presenter.OnCancel();
        }
    }
}
